package com.demo9;

public class ArrayDemo {
    public static void main(String[] args) {
        int[] arr = {23,100,80,12,50};
        //java实现冒泡排序的效果 从大到小的效果如下所示
        for(int m =0;m<arr.length-1;m++){
            for (int i=0;i<arr.length-1-m;i++){
                if(arr[i]>arr[i+1]){
                    int tmp = arr[i];
                    arr[i] = arr[i+1];

                    arr[i+1] = tmp;
                }
            }
        }

        System.out.println("排序后"+ArrayToString(arr));

    }

    public static StringBuilder ArrayToString(int[] arr){
        StringBuilder string = new StringBuilder();
        string.append("[");
        for (int i=0;i<arr.length;i++){
            if(i==arr.length-1){
                string.append(arr[i]);
            }else{
                string.append(arr[i]+",");
            }
        }
        string.append("]");

        return string;
    }
}
